home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / gui / validators.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  4KB  |  103 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4. import wx
  5. import string
  6.  
  7. class SimpleValidator(wx.PyValidator):
  8.     
  9.     def __init__(self, char_callbacks, str_callbacks):
  10.         if callable(char_callbacks):
  11.             char_callbacks = (char_callbacks,)
  12.         
  13.         if callable(str_callbacks):
  14.             str_callbacks = (str_callbacks,)
  15.         
  16.         wx.PyValidator.__init__(self)
  17.         self.char_callbacks = char_callbacks
  18.         self.str_callbacks = str_callbacks
  19.         self.Bind(wx.EVT_CHAR, self.OnChar)
  20.         self.Bind(wx.EVT_TEXT, self.OnText)
  21.  
  22.     
  23.     def OnChar(self, event):
  24.         key = event.GetKeyCode()
  25.         if key < 0 and key > 255 and chr(key) not in string.printable or self.check_char(chr(key)):
  26.             event.Skip()
  27.             self._last_ok_val = event.EventObject.Value
  28.             return None
  29.         
  30.         if not wx.Validator_IsSilent():
  31.             wx.Bell()
  32.         
  33.  
  34.     
  35.     def OnText(self, event):
  36.         s = event.EventObject.Value
  37.         if not self.check_string(s):
  38.             event.EventObject.Value = self._last_ok_val
  39.         else:
  40.             self._last_ok_val = s
  41.             event.Skip()
  42.  
  43.     
  44.     def check_char(self, c):
  45.         return (all,)((lambda .0: for cb in .0:
  46. cb(c))(self.char_callbacks))
  47.  
  48.     
  49.     def check_string(self, s):
  50.         return (all,)((lambda .0: for cb in .0:
  51. cb(s))(self.str_callbacks))
  52.  
  53.     
  54.     def Clone(self):
  55.         return SimpleValidator(self.char_callbacks, self.str_callbacks)
  56.  
  57.     
  58.     def Validate(self, win):
  59.         return 1
  60.  
  61.     
  62.     def TransferToWindow(self):
  63.         return True
  64.  
  65.     
  66.     def TransferFromWindow(self):
  67.         return True
  68.  
  69.     
  70.     def __add__(self, other):
  71.         return SimpleValidator(self.char_callbacks + other.char_callbacks, self.str_callbacks + other.str_callbacks)
  72.  
  73.  
  74.  
  75. def string_check(type):
  76.     valid = getattr(string, type)
  77.     return (lambda s: (all,)((lambda .0: for c in .0:
  78. c in valid)(s))
  79. )
  80.  
  81.  
  82. def AlphaOnly():
  83.     return SimpleValidator((string_check('letters'),), ())
  84.  
  85.  
  86. def DigitsOnly():
  87.     return SimpleValidator((string_check('digits'),), ())
  88.  
  89.  
  90. def LengthLimit(n):
  91.     return SimpleValidator(((),), ((lambda s: len(s) <= n),))
  92.  
  93.  
  94. def NumericLimit(start, stop = None):
  95.     if stop is None:
  96.         start = 0
  97.         stop = start
  98.     
  99.     return None + DigitsOnly()((SimpleValidator, ()), (lambda s: if not not s:
  100. passNone if int(s) <= int(s) else int(s) <= stop))
  101.  
  102. common_validators = dict(d = DigitsOnly, s = AlphaOnly)
  103.